package com.sajus.web.billing.ejb.domain;

import javax.persistence.EntityManager;

import com.sajus.web.billing.ejb.data.model.PersistentObject;


public class DomainObject<T extends PersistentObject> {
	private T delegate;

	
	/* use this constructor when creating
	 * classes from existing, persisted entities
	 */
	public DomainObject(T delegate) {
		super();
		this.delegate = delegate;
		
	}
	

	/*
	 * TODO: expose it to the outside world only for 
	 * persistence reasons
	 */
	public T getDelegate(EntityManager em) {
		if (em == null) return null;
		return getDelegate();
	}
	
	public T getDelegate() {
		return delegate;
	}
	
	public void setDelegate(T delegate) {
		this.delegate = delegate;
	}

	public void attach() {
		this.delegate = (T)delegate.attach();
	}

}
